/*
author:烨然Hvril(https://www.hvril.cn)
date:2023-07
copyright:烨拓科讯技术团队[Hauiteut]&烨然Hvril(YeRanHvril)
name:科特时钟KaTrClock
describe:Kete clock is the first product released by the technical team of Yetuo Kexun, 
originally the ACUI glow tube LED clock, 
won the "Gansu Telecom Cup" Gansu Province 37th Provincial Science and Technology Innovation Competition Provincial Second Prize, 
Kete Clock is the first version of its improvement, 
the version number is "v1.0.1"
version:v1.0.1
*/
// Icon library
#include "./Images.h"
#include "./Font.h"
#include "./Seasons_icon.h"
#include "./Loading_icon.h"
// TFT screen
#include "SPI.h"
#include "TFT_eSPI.h"
#include <TFT_eWidget.h>
// WIFI
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
// Resource loading functions

TFT_eSPI tft = TFT_eSPI(); // Declare the TFT screen

void SetupLogin()
{
    tft.pushImage(88, 48, 147, 39, hauiteut_cn_logo);
    tft.pushImage(88, 120, 48, 48, loading_state_0);
    // WIFI aera
    int i = 0;
    WiFi.begin();
    Serial.print("正在连接已存在的WIFI节点信息");
    delay(400);
    tft.pushImage(88, 120, 48, 48, loading_state_10);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        i++;
        if (i == 12)
        {
            Serial.println("已有WiFi数据连接失败,进一键配网模式");
            WiFi.mode(WIFI_STA);
            WiFi.beginSmartConfig();
            while (WiFi.status() != WL_CONNECTED)
            {
                delay(500);
                Serial.println(".");
                if (WiFi.smartConfigDone() == 0)
                {
                    Serial.println("正在等待联网数据,请使用乐鑫官方App进行一件配网");
                    tft.pushImage(88, 120, 48, 48, loading_state_87);
                }
                else if (WiFi.smartConfigDone() == 1)
                {
                    Serial.println("已接受数据,开始联网");
                }
            }
        }
    }
    delay(1000);
    Serial.println(".");
    Serial.println("IP:");
    Serial.println(WiFi.localIP());
    tft.pushImage(88, 120, 48, 48, loading_state_93);
}
// Setup function
void setup()
{
    Serial.begin(9600);        // Serial port baud rate 9600
    tft.begin();               // Initialize the TFT screen
    tft.fillScreen(TFT_BLACK); // Fill black
    tft.setRotation(1);        // The screen orientation is landscape
    tft.setSwapBytes(true);    // Screen color mode

    tft.pushImage(88, 120, 48, 48, loading_state_100);
}
